package com.ehi.common.jersey.status;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum ResponseTypeCode {

    NOT_FOUND(404, "RESOURCE_NOT_FOUND"),

    PARAMETER_INVALID(400, "PARAMETER_INVALID"),

    QUOTE_EXCEPTION(400, "QUOTE_EXCEPTION"),

    FORBIDDEN(403, "FORBIDDEN"),

    METHOD_NOT_ALLOWED(405, "METHOD_NOT_ALLOWED"),

    UNAUTHORIZED(401, "UNAUTHORIZED"),

    NOT_ACCEPTABLE(406, "NOT_ACCEPTABLE"),

    API_UPDATED(409, "API_UPDATED"),

    UNSUPPORTED_MEDIA_TYPE(415, "UNSUPPORTED_MEDIA_TYPE"),

    SERVER_ERROR(500, "SERVER_ERROR");

    private int typeCode;

    private String errorType;

    ResponseTypeCode(int typeCode, String errorType) {
        this.typeCode = typeCode;
        this.errorType = errorType;
    }

    public int getTypeCode() {
        return typeCode;
    }

    public String getErrorType() {
        return errorType;
    }

    @JsonValue
    public String toValue() {
        return errorType;
    }

    @JsonCreator
    public static ResponseTypeCode fromErrorType(String errorType) {
        for (ResponseTypeCode productLine : ResponseTypeCode.values()) {
            if (productLine.errorType.equalsIgnoreCase(errorType)) {
                return productLine;
            }
        }
        throw new IllegalArgumentException("Unsupported ResponseStatusCode, errorType=" + errorType);
    }

}
